//拉动计划生成领料清单
OB.Emes_ActionButton.Generate_Materail_Button = function(params, view) {
	var view = view.activeView.viewGrid;
	var records = view.getSelectedRecords();
	var length = records.getLength();

	if (length) {
		isc.confirm("确定生成领料清单？", function(ok) {
			if (ok) {
				// 选择纪录行
				var selectRecords = [];
				for ( var i = 0; i < length; i++) {
					selectRecords.push(records[i].id);
				}
				OB.RemoteCallManager.call(
					"com.mes.handler.plan.GenerateMaterialHandler", {
						ids : selectRecords.join(",")
					}, {}, function(request, data, response) {
						if (data.flag) {
							view.refreshGrid();
							isc.showMessage(data.message);
						} else {
							isc.showMessage(data.message);
						}
					});
			}
		});
	} else {
		isc.showMessage("请选择纪录！");
	}
};
//作业工单下发
OB.Emes_ActionButton.JobOrder_Generate_Materail_Button = function(params, view) {
    var view = view.activeView.viewGrid;
    var records = view.getSelectedRecords();
    var length = records.getLength();

    if (length) {
        isc.confirm("确定生成领料单？", function(ok) {
            if (ok) {
                // 选择纪录行
                var selectRecords = [];
                for ( var i = 0; i < length; i++) {
                    selectRecords.push(records[i].id);
                }
                OB.RemoteCallManager.call(
                    "com.mes.handler.plan.JobOrderGenerateMaterialHandler", {
                        ids : selectRecords.join(",")
                    }, {}, function(request, data, response) {
                        if (data.flag) {
                            view.refreshGrid();
                            isc.showMessage(data.message);
                        } else {
                            isc.showMessage(data.message);
                        }
                    });
            }
        });
    } else {
        isc.showMessage("请选择纪录！");
    }
};
//一键派工
OB.Emes_ActionButton.manuOrderBatchAssign = function(params, win) {
    isc.confirm("一键派工将会将当前时间段和下个时间段工单自动派工到飞织机，是否继续？", function(ok) {
        if (ok) {
            OB.RemoteCallManager.call(
                "com.mes.handler.plan.ManuOrderGenerateTimeHandler", {}, {}, function (request, data) {
                    OB.Emes_ActionButton.AssignOrders = {ids: ''};
                    if (data.flag) {
                        win.refresh();
                        if (data.ids == '') {
                            isc.showMessage("将当前时间段和下个时间段无可派工工单！");
                            return;
                        } else {
                            isc.showMessage(data.message);
                            OB.Emes_ActionButton.AssignOrders = {ids: data.ids, generate: true};
                        }
                    } else {
                        isc.showMessage(data.message);
                    }
                    var params = {
                        width: '90%',
                        height: '90%',
                        url: "web/com.mes/html/FZJpaigong.html"
                    };
                    OB.Emes_ActionButton.orderAssignOpenWindow = win;
                    isc.EMES_Window_View.create(params).show();
                });
        }
    });
};

// 拉动计划生成计划开工时间
OB.Emes_ActionButton.ManuorderPlanGenerate = function(params, view) {
	isc.confirm("确定生成计划开工时间？", function(ok) {
		if (ok) {
			OB.RemoteCallManager.call(
				"com.mes.handler.plan.ManuOrderGenerateTimeHandler", {}, {}, function(request, data) {
					if (data.flag) {
						view.refresh();
						isc.showMessage(data.message);
					} else {
						isc.showMessage(data.message);
					}
				});
		}
	});
};